/*
 * Created: Author: Aléx Carvalho / Date: Feb 22, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-06-12 03:38:01 +0000 (Fri, 12 Jun 2015) $
 */
package com.cpm.view.zk;

import com.cpm.aggregate.StyleAttribute;
import com.cpm.view.Element;
import com.cpm.view.Icon;
import org.zkoss.zhtml.I;
import org.zkoss.zk.ui.Component;

public class IconElement implements Element<Component> {
    
    private final I component = new I();
    
    private final Icon icon;

    public IconElement(Icon icon) { this.icon = icon; }
    
    @Override
    public Component getElement() {
        final StringBuilder style = new StringBuilder();
        
        icon.getIterator().forEachRemaining( next -> style.append(((StyleAttribute) next).getValue()) );
        
        component.setDynamicProperty("class", icon.toString() );
        
        String styleValue = style.toString();
        
        if (!styleValue.isEmpty()){
            component.setDynamicProperty("style", styleValue );
        }
        
        return component;
    }
}
